import json
name_dict = {}
message_dict = {}
a = 0
while a != 3:
    a = int(input("请选择：1.注册 2.查询 3.退出"))
    file = open('test.txt', 'r')
    js = file.read()
    name_dict = json.loads(js)
    file.close()
    # print(name_dict)
    if (a == 1):
        user_name = input("请输入用户名")
        if user_name in name_dict.keys():
            print("用户已存在")
        else:
            password = input("请输入密码")
            age = input("请输入年龄")
            name_dict[user_name] =message_dict
            message_dict["password"]=password
            message_dict["age"] = age
            print("用户注册成功")
            js = json.dumps(name_dict)
            file = open('test.txt', 'w')
            file.write(js)
            file.close()

    elif(a == 2):
        user_name = input("请输入用户名")
        if user_name in name_dict.keys():
            # print(name_dict)
            print("{ username:",user_name,":",name_dict.get(user_name),"}")
            print("用户已注册")
        else:
            print("用户不存在")
    else:
        print("退出系统")
print()